﻿using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;
using System.Text;
using System.Web.Services;


public partial class AddProperty : System.Web.UI.Page
{
    DataTable table = new DataTable("Customers");
    string p_id = null;
    string c_id;
    string t_id;
    private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
    {
        byte[] Ret;
        try
        {
            using (MemoryStream ms = new MemoryStream())
            {
                imageToConvert.Save(ms, formatOfImage);
                Ret = ms.ToArray();
            }
        }
        catch (Exception) { throw; }
        return Ret;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["p_id"] == null)
        {
            var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random = new Random();
            var p_id = new string(
                Enumerable.Repeat(chars, 8)
                          .Select(s => s[random.Next(s.Length)])
                          .ToArray());




            //Session["p_id"] = p_id;
            SqlConnection con = null;

            con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
            con.Open();


            SqlCommand cmd1 = new SqlCommand("SELECT p_id FROM properties where p_id='" + p_id + "'", con);

            SqlDataReader dr2 = cmd1.ExecuteReader();


            if (dr2.Read())
            {
                var chars1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random1 = new Random();
                var n_id = new string(
                    Enumerable.Repeat(chars1, 8)
                              .Select(s => s[random1.Next(s.Length)])
                              .ToArray());


                Request.QueryString["p_id"] = n_id;

            }






            else
            {
                Session["p_id"]= p_id;

            }
            dr2.Close();
            con.Close();





        }

        else
        {
            p_id = Session["p_id"].ToString();
        }











        if (Session["t_id"] == null)
        {
            var chars2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random2 = new Random();
            var t_id = new string(
                Enumerable.Repeat(chars2, 8)
                          .Select(s => s[random2.Next(s.Length)])
                          .ToArray());

            Session["t_id"] = t_id;
        }

        else
        {
            t_id = Session["t_id"].ToString();
        }
        //Session["myTable"] = table;
     //   if (!IsPostBack)
     //   {
            table.Columns.Add("action_");
            table.Columns.Add("p_id");
            table.Columns.Add("t_id");
            table.Columns.Add("deal_status");
            table.Columns.Add("created");
            table.Columns.Add("update_");
            table.Columns.Add("min_");
            table.Columns.Add("hrs");
            table.Columns.Add("fast_reminder");
            table.Columns.Add("day_");
            table.Columns.Add("agent");
            table.Columns.Add("sec_agent");
            table.Columns.Add("min1");    
            table.Columns.Add("hr");
            table.Columns.Add("rank");
            table.Columns.Add("commission");
            table.Columns.Add("sig");
            table.Columns.Add("refer");
            table.Columns.Add("cust_rank");
            table.Columns.Add("cust_refer");
            table.Columns.Add("comment");
            table.Columns.Add("terms");
            table.Columns.Add("to_do");
            table.Columns.Add("cus_to_do");
            table.Columns.Add("status_");
            table.Columns.Add("full_day");
            table.Columns.Add("to_do_msg");
            table.Columns.Add("to_do_date");
            table.Columns.Add("to_min");
            table.Columns.Add("to_hr");
            table.Columns.Add("added_by");
            table.Columns.Add("cus_deal_status");
            table.Columns.Add("cust_stat");
            table.Columns.Add("cust_reminder");

  //      }


        if (Session["myTable"] == null)
        {
            Session["myTable"] = table;
        }

        else
        {


            table = Session["myTable"] as DataTable;

        }


        table = Session["myTable"] as DataTable;


        //TextBox16.Text = "0";

        if (Session["email"] == null)
        {
            Session["email"] = "admin";
        }
        // Label1.Text = Session["email"].ToString();
        // txtcreate.Text = System.DateTime.Now.ToString();
        txtagent.Text = Session["email"].ToString();


    }
    protected void DropDownList5_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        //Session["type"] = DropDownList5.SelectedValue;
        //Session["proptype"] = DropDownList6.SelectedValue;


    }

    protected void ok(object sender, System.EventArgs e)
    {
        if (Session["t_id"] == null)
        {
            var chars3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var random3 = new Random();
            var t_id = new string(
                Enumerable.Repeat(chars3, 8)
                          .Select(s => s[random3.Next(s.Length)])
                          .ToArray());
            //t_id = letter + number;
            Session["t_id"] = t_id;
        }

        else
        {
            t_id = Session["t_id"].ToString();
        }

         try
        {
        table.Rows.Add(p_id, p_id, t_id, DropDownList4.SelectedValue, txtdate.Text, txtupdate.Text, ddlhr.SelectedValue, ddlmint.SelectedValue, DropDownList52.SelectedValue, txtFR.Text, ddlhr0.SelectedValue, ddlmint0.SelectedValue, txtagent.Text, DropDownList6.SelectedValue, DropDownList53.SelectedValue, TextBox59.Text, txtcommsin.Text, DropDownList54.SelectedValue, DropDownList55.SelectedValue, TextBox60.Text, txtcomment.Text, txtterms.Text, DropDownList28.SelectedValue, TextBox61.Text, DropDownList29.SelectedValue, DropDownList30.SelectedValue, txtmsg.Text, txttododate.Text, ddlhr1.SelectedValue, ddlmint1.SelectedValue, "Admin", TextBox57.Text, TextBox78.Text, TextBox58.Text);

        }

         catch (Exception err)
         {
             Label2.Text = err.Message;

         }


         GridView1.DataSource = table;
         GridView1.DataBind();
         Session["myTable"] = table;

         string path1 = Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc");
         if (!Directory.Exists(path1))
         {
             Directory.CreateDirectory(path1);
         }

        if (FileUpload2.HasFile)
        {

            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc/" + System.IO.Path.GetFileName(hpf.FileName)));

                    SqlConnection co = null;
                    co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                    co.Open();

                    SqlCommand cmd = new SqlCommand("Insert into files values(@id,@FileName ,@FilePath )", co);
//id nvarchar (50),
//FileName nvarchar (50),
//FilePath nvarchar (50)


                    cmd.Parameters.AddWithValue("@id", Session["p_id"]);
                    cmd.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hpf.FileName));
                    cmd.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/" + "Doc/" + hpf.FileName ));
                   

                    cmd.ExecuteNonQuery();
                    co.Close();
                }
            }
        }

      

        DropDownList4.SelectedValue = "";
        txtdate.Text = "";
        txtupdate.Text = "";
        ddlhr.SelectedValue = "";
        ddlmint1.SelectedValue = "";
        DropDownList52.SelectedValue = "";
        txtFR.Text = "";
        ddlhr0.SelectedValue = "";
        ddlmint0.SelectedValue = "";
        DropDownList54.SelectedValue = "";
        txtcommsin.Text = "";
        DropDownList54.SelectedValue = "";
        DropDownList55.SelectedValue = "";
        TextBox56.Text = "";
        txtcomment.Text = "";
        txtterms.Text = "";
        DropDownList28.SelectedValue = "";

        DropDownList29.SelectedValue = "";
        DropDownList30.SelectedValue = "";
        txtmsg.Text = "";
        txttododate.Text = "";
        ddlhr1.SelectedValue = "";
        ddlmint1.SelectedValue = "";


    }

    protected void Save_Click(object sender, System.EventArgs e)
    {

       
        SqlConnection conn = null;
        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();
        string filename = FileUpload1.PostedFile.FileName.ToString();



       // System.Drawing.Image imag = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
        SqlCommand cmd = new SqlCommand("Insert into properties values(@frontend ,@type ,@p_id ,@agent_name ,@p_type ,@cust_type ,@fname ,@lname ,@email_add ,@phone_no ,@house_no ,@city ,@street ,@zip_code ,@country ,@neigh_hood ,@p_neighbor ,@house_number ,@apartment_number ,@block ,@sub ,@roomno ,@prop_cond ,@cust_propcond ,@floorno ,@total_flr ,@build_cond ,@cust_b_cond ,@age_building, @n_of_res ,@b_pri ,@cust_build ,@parking ,@cust_parking ,@furnt ,@cust_furnt ,@basement ,@cust_base, @storage ,@cust_storage ,@ac ,@cust_ac ,@toilets ,@cust_toilets ,@toilets1 ,@cust_toilets1,@shower ,@cust_shower ,@roof ,@kitchen ,@cust_kitchen ,@view1 ,@cust_view1 ,@f_view ,@cust_view ,@garden ,@cust_garden ,@evacuation_date ,@cust_evacuation_date ,@land ,@cust_land ,@balconies  ,@balconies_no ,@main ,@build_permit ,@balconies_size ,@sign ,@balconies1 ,@balconies_size1 ,@sign1, @cust_build_permit ,@boiler ,@cust_boiler ,@safe_room ,@custs_room ,@elevator ,@cust_elevator ,@permises ,@Plot_sign ,@propertysize ,@propertysizesign ,@price ,@sign4 ,@oldprice ,@sign2  ,@price_red ,@p_north ,@p_south ,@p_east ,@p_west ,@p_smart ,@p_alarm ,@p_bars ,@p_handi ,@p_teather ,@p_gym ,@p_zacuji ,@p_pool ,@c_check ,@status1 ,@adding_date ,@adding_by ,@toilet3 ,@toilet3_cust,@toilet4 ,@toilet4_cust,@toilet5 ,@toilet5_cust ,@balconies3 ,@balconies3_size ,@sign3 ,@balconies4 ,@balconies4_size ,@balconies4_sign4 ,@balconies5 ,@balconies5_size ,@balconies5_sign5  )", conn);

        cmd.Parameters.AddWithValue("@frontend", DropDownList31.SelectedValue);
        cmd.Parameters.AddWithValue("@type", "For Sale");
        cmd.Parameters.AddWithValue("@p_id", Session["p_id"].ToString());
        cmd.Parameters.AddWithValue("@agent_name", DropDownList7.SelectedValue);
        cmd.Parameters.AddWithValue("@p_type", d6.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_type", TextBox4.Text);
        cmd.Parameters.AddWithValue("@fname", txtfname1.Text);
        cmd.Parameters.AddWithValue("@lname", txtlname1.Text);
        cmd.Parameters.AddWithValue("@email_add", TextBox22.Text);
        cmd.Parameters.AddWithValue("@phone_no", TextBox21.Text);
        cmd.Parameters.AddWithValue("@house_no", TextBox3.Text);
        cmd.Parameters.AddWithValue("@city", TextBox30.Text);
        cmd.Parameters.AddWithValue("@street", TextBox31.Text);
        cmd.Parameters.AddWithValue("@zip_code", TextBox24.Text);
        cmd.Parameters.AddWithValue("@country", TextBox23.Text);
        cmd.Parameters.AddWithValue("@neigh_hood", TextBox32.Text);
        cmd.Parameters.AddWithValue("@p_neighbor", TextBox35.Text);
        cmd.Parameters.AddWithValue("@house_number", TextBox13.Text);
        cmd.Parameters.AddWithValue("@apartment_number", TextBox14.Text);
        cmd.Parameters.AddWithValue("@block", TextBox62.Text);
        cmd.Parameters.AddWithValue("@sub", TextBox63.Text);
        cmd.Parameters.AddWithValue("@roomno", TextBox36.Text);
        cmd.Parameters.AddWithValue("@prop_cond", DropDownList37.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_propcond", TextBox9.Text);
        cmd.Parameters.AddWithValue("@floorno", TextBox25.Text);
        cmd.Parameters.AddWithValue("@total_flr", TextBox26.Text);
        cmd.Parameters.AddWithValue("@build_cond", DropDownList42.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_b_cond", TextBox5.Text);
        cmd.Parameters.AddWithValue("@age_building", TextBox12.Text);
        cmd.Parameters.AddWithValue("@n_of_res", TextBox37.Text);
        cmd.Parameters.AddWithValue("@b_pri", DropDownList43.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_build", TextBox7.Text);
        cmd.Parameters.AddWithValue("@parking", ddlparking.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_parking", txtpark.Text);
        cmd.Parameters.AddWithValue("@furnt", DropDownList18.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_furnt", txtfurniture.Text);
        cmd.Parameters.AddWithValue("@basement", DropDownList10.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_base", TextBox27.Text);
        cmd.Parameters.AddWithValue("@storage", DropDownList11.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_storage", TextBox34.Text);
        cmd.Parameters.AddWithValue("@ac", DropDownList12.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_ac", TextBox54.Text);
        cmd.Parameters.AddWithValue("@toilets", DropDownList19.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_toilets", txttoilets.Text);
        cmd.Parameters.AddWithValue("@toilets1", DropDownList56.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_toilets1", TextBox2.Text);
        cmd.Parameters.AddWithValue("@toilet3", DropDownList57.SelectedValue);
        cmd.Parameters.AddWithValue("@toilet3_cust", TextBox64.Text);
        cmd.Parameters.AddWithValue("@toilet4", DropDownList59.SelectedValue);
        cmd.Parameters.AddWithValue("@toilet4_cust", TextBox65.Text);
        cmd.Parameters.AddWithValue("@toilet5", DropDownList60.SelectedValue);
        cmd.Parameters.AddWithValue("@toilet5_cust", TextBox66.Text);
        cmd.Parameters.AddWithValue("@shower", DropDownList20.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_shower", TextBox16.Text);
        cmd.Parameters.AddWithValue("@roof", TextBox33.Text);
        cmd.Parameters.AddWithValue("@kitchen", DropDownList16.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_kitchen", TextBox20.Text);
        cmd.Parameters.AddWithValue("@view1", DropDownList36.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_view1", TextBox8.Text);
        cmd.Parameters.AddWithValue("@f_view", DropDownList39.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_view", TextBox11.Text);
        cmd.Parameters.AddWithValue("@garden", DropDownList25.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_garden", TextBox15.Text);
        cmd.Parameters.AddWithValue("@evacuation_date", DropDownList33.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_evacuation_date", TextBox10.Text);
        cmd.Parameters.AddWithValue("@land", DropDownList34.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_land", TextBox38.Text);
        cmd.Parameters.AddWithValue("@balconies", txtBalconies.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies_size", TextBox6.Text);
        cmd.Parameters.AddWithValue("@sign", DropDownList46.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies1", txtBalconies0.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies_size1", TextBox48.Text);
        cmd.Parameters.AddWithValue("@sign1", DropDownList47.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies3", txtBalconies1.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies3_size", TextBox67.Text);
        cmd.Parameters.AddWithValue("@sign3", DropDownList61.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies4", txtBalconies2.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies4_size", TextBox68.Text);
        cmd.Parameters.AddWithValue("@balconies4_sign4", DropDownList62.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies5", txtBalconies3.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies5_size", TextBox69.Text);
        cmd.Parameters.AddWithValue("@balconies5_sign5", DropDownList63.SelectedValue);
        cmd.Parameters.AddWithValue("@balconies_no", TextBox49.Text);
        cmd.Parameters.AddWithValue("@main", TextBox39.Text);
        cmd.Parameters.AddWithValue("@build_permit", DropDownList24.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_build_permit", TextBox45.Text);
        cmd.Parameters.AddWithValue("@boiler", DropDownList32.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_boiler", TextBox46.Text);
        cmd.Parameters.AddWithValue("@safe_room", DropDownList44.SelectedValue);
        cmd.Parameters.AddWithValue("@custs_room", TextBox53.Text);
        cmd.Parameters.AddWithValue("@elevator", DropDownList50.SelectedValue);
        cmd.Parameters.AddWithValue("@cust_elevator", TextBox47.Text);
        cmd.Parameters.AddWithValue("@permises", txtProperty.Text);
        cmd.Parameters.AddWithValue("@Plot_sign", DropDownList58.SelectedValue);
        cmd.Parameters.AddWithValue("@propertysize", TextBox40.Text);
        cmd.Parameters.AddWithValue("@propertysizesign", DropDownList41.SelectedValue);
        cmd.Parameters.AddWithValue("@price", txtPrice.Text);
        cmd.Parameters.AddWithValue("@sign4", DropDownList49.SelectedValue);
        cmd.Parameters.AddWithValue("@oldprice", txtOldPrice.Text);
        cmd.Parameters.AddWithValue("@sign2", DropDownList51.SelectedValue);
        cmd.Parameters.AddWithValue("@price_red", TextBox52.Text);

        cmd.Parameters.AddWithValue("@p_north", CheckBox9.Checked);
        cmd.Parameters.AddWithValue("@p_south", CheckBox10.Checked);
        cmd.Parameters.AddWithValue("@p_east", CheckBox11.Checked);
        cmd.Parameters.AddWithValue("@p_west", CheckBox12.Checked);
        cmd.Parameters.AddWithValue("@p_smart", CheckBox1.Checked);
        cmd.Parameters.AddWithValue("@p_alarm", CheckBox2.Checked);
        cmd.Parameters.AddWithValue("@p_bars", CheckBox3.Checked);
        cmd.Parameters.AddWithValue("@p_handi", CheckBox4.Checked);
        cmd.Parameters.AddWithValue("@p_teather", CheckBox5.Checked);
        cmd.Parameters.AddWithValue("@p_gym", CheckBox6.Checked);
        cmd.Parameters.AddWithValue("@p_zacuji", CheckBox7.Checked);
        cmd.Parameters.AddWithValue("@p_pool", CheckBox8.Checked);
        cmd.Parameters.AddWithValue("@c_check", CheckBox13.Checked);

        cmd.Parameters.AddWithValue("@comment", TextBox79.Text);			


        cmd.Parameters.AddWithValue("@status1", "1");
        cmd.Parameters.AddWithValue("@adding_date", System.DateTime.Now);
        cmd.Parameters.AddWithValue("@adding_by", Session ["email"]);


        cmd.ExecuteNonQuery();
        string path = Server.MapPath("upload/" + Session["p_id"] + "/" + "Image");
        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        if (FileUpload1.HasFile)
        {

            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Image/" + System.IO.Path.GetFileName(hpf.FileName)));

                    SqlConnection co = null;
                    co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                    co.Open();

                    SqlCommand cmd1 = new SqlCommand("Insert into images values(@id,@FileName ,@FilePath,@f_end )", co);
                    //id nvarchar (50),
                    //FileName nvarchar (50),
                    //FilePath nvarchar (50)


                    cmd1.Parameters.AddWithValue("@id", Session["p_id"]);
                    cmd1.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hpf.FileName));
                    cmd1.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/" + "Image/" + hpf.FileName));
                    cmd1.Parameters.AddWithValue("@f_end", DropDownList31.SelectedValue);


                    cmd1.ExecuteNonQuery();
                    co.Close();
                    
                
                }
            }
        }

        if (table.Rows.Count == 0)
        {
            string path1 = Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc");
            if (!Directory.Exists(path1))
            {
                Directory.CreateDirectory(path1);
            }

            if (FileUpload2.HasFile)
            {

                HttpFileCollection hfc = Request.Files;
                for (int i = 0; i < hfc.Count; i++)
                {
                    HttpPostedFile hpf = hfc[i];
                    if (hpf.ContentLength > 0)
                    {
                        hpf.SaveAs(Server.MapPath("upload/" + Session["p_id"] + "/" + "Doc/" + System.IO.Path.GetFileName(hpf.FileName)));

                        SqlConnection co = null;
                        co = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
                        co.Open();

                        SqlCommand cmd2 = new SqlCommand("Insert into files values(@id,@FileName ,@FilePath )", co);
                        //id nvarchar (50),
                        //FileName nvarchar (50),
                        //FilePath nvarchar (50)


                        cmd2.Parameters.AddWithValue("@id", Session["p_id"]);
                        cmd2.Parameters.AddWithValue("@FileName", System.IO.Path.GetFileName(hpf.FileName));
                        cmd2.Parameters.AddWithValue("@FilePath", ("upload/" + Session["p_id"] + "/" + "Doc/" + hpf.FileName));


                        cmd.ExecuteNonQuery();
                        co.Close();

                    }
                }
            }




            SqlCommand cmd1 = new SqlCommand("insert into task (action_,p_id,t_id,deal_status,created,update_,hrs,min_,fast_reminder,day_,hr,min1,agent,sec_agent,rank,cust_rank,commission,sig,refer,cust_refer,comment,terms,to_do,cus_to_do,status_,full_day,to_do_msg,to_do_date,to_hr,to_min,added_by,cus_deal_status,cust_stat,cust_reminder) values  (@action_,@p_id ,@t_id ,@deal_status ,@created ,@update_ ,@min_ ,@hrs ,@fast_reminder ,@day_ ,@hr ,@min1 ,@agent ,@sec_agent ,@rank ,@cust_rank ,@commission ,@sig ,@refer ,@cust_refer ,@comment ,@terms ,@to_do ,@cus_to_do ,@status_ ,@full_day ,@to_do_msg ,@to_do_date ,@to_hr ,@to_min,@added_by,@cus_deal_status,@cust_stat,@cust_reminder)", conn);
            cmd1.Parameters.AddWithValue("@action_", "0");
            cmd1.Parameters.AddWithValue("@p_id ", Session["p_id"]);
            cmd1.Parameters.AddWithValue("@t_id ", Session["t_id"]);
            cmd1.Parameters.AddWithValue("@deal_status ", DropDownList4.SelectedValue);
            cmd1.Parameters.AddWithValue("@created ", txtdate.Text);
            cmd1.Parameters.AddWithValue("@update_ ", txtupdate.Text);
            cmd1.Parameters.AddWithValue("@hrs", ddlhr.SelectedValue);
            cmd1.Parameters.AddWithValue("@min_", ddlmint.SelectedValue);
            cmd1.Parameters.AddWithValue("@fast_reminder", DropDownList52.SelectedValue);
            cmd1.Parameters.AddWithValue("@day_ ", txtFR.Text);
            cmd1.Parameters.AddWithValue("@hr", ddlhr0.SelectedValue);
            cmd1.Parameters.AddWithValue("@min1", ddlmint0.SelectedValue);
            cmd1.Parameters.AddWithValue("@agent", txtagent.Text);
            cmd1.Parameters.AddWithValue("@sec_agent", DropDownList6.SelectedValue);
            cmd1.Parameters.AddWithValue("@rank", DropDownList53.SelectedValue);
            cmd1.Parameters.AddWithValue("@cust_rank", TextBox59.Text);
            cmd1.Parameters.AddWithValue("@commission", txtcommsin.Text);
            cmd1.Parameters.AddWithValue("@sig", DropDownList54.SelectedValue);
            cmd1.Parameters.AddWithValue("@refer", DropDownList55.SelectedValue);
            cmd1.Parameters.AddWithValue("@cust_refer", TextBox60.Text);
            cmd1.Parameters.AddWithValue("@comment", txtcomment.Text);
            cmd1.Parameters.AddWithValue("@terms", txtterms.Text);
            cmd1.Parameters.AddWithValue("@to_do", DropDownList28.SelectedValue);
            cmd1.Parameters.AddWithValue("@cus_to_do", TextBox61.Text);
            cmd1.Parameters.AddWithValue("@status_ ", DropDownList29.SelectedValue);
            cmd1.Parameters.AddWithValue("@full_day", DropDownList30.SelectedValue);
            cmd1.Parameters.AddWithValue("@to_do_msg", txtmsg.Text);
            cmd1.Parameters.AddWithValue("@to_do_date", txttododate.Text);
            cmd1.Parameters.AddWithValue("@to_hr", ddlhr1.SelectedValue);
            cmd1.Parameters.AddWithValue("@to_min", ddlmint1.Text);

            cmd1.Parameters.AddWithValue("added_by", Session["email"]);
            cmd1.Parameters.AddWithValue("@cus_deal_status", TextBox57.Text);
            cmd1.Parameters.AddWithValue("@cust_stat", TextBox78.Text);
            cmd1.Parameters.AddWithValue("@cust_reminder", TextBox58.Text);

            cmd1.ExecuteNonQuery();
        }
        else
        {


            for (int i = 0; i < table.Rows.Count; i++)
            {
                string action_ = table.Rows[i]["action_"].ToString().Trim();
                string pid = table.Rows[i]["p_id"].ToString().Trim();
                string tid = table.Rows[i]["t_id"].ToString().Trim();
                string deal_status = table.Rows[i]["deal_status"].ToString().Trim();
                string created = table.Rows[i]["created"].ToString().Trim();
                string update_ = table.Rows[i]["update_"].ToString().Trim();
                string min_ = table.Rows[i]["min_"].ToString().Trim();
                string hrs = table.Rows[i]["hrs"].ToString().Trim();
                string fast_reminder = table.Rows[i]["fast_reminder"].ToString().Trim();
                string day_ = table.Rows[i]["day_"].ToString().Trim();
                string agent = table.Rows[i]["agent"].ToString().Trim();
                string sec_agent = table.Rows[i]["sec_agent"].ToString().Trim();
                string min1 = table.Rows[i]["min1"].ToString().Trim();
                string hr = table.Rows[i]["hr"].ToString().Trim();
                string rank = table.Rows[i]["rank"].ToString().Trim();
                string commission = table.Rows[i]["commission"].ToString().Trim();
                string sig = table.Rows[i]["sig"].ToString().Trim();
                string refer = table.Rows[i]["refer"].ToString().Trim();
                string cust_rank = table.Rows[i]["cust_rank"].ToString().Trim();
                string cust_refer = table.Rows[i]["cust_refer"].ToString().Trim();
                string comment = table.Rows[i]["comment"].ToString().Trim();
                string terms = table.Rows[i]["terms"].ToString().Trim();
                string to_do = table.Rows[i]["to_do"].ToString().Trim();
                string cus_to_do = table.Rows[i]["cus_to_do"].ToString().Trim();
                string status_ = table.Rows[i]["status_"].ToString().Trim();
                string full_day = table.Rows[i]["full_day"].ToString().Trim();
                string to_do_msg = table.Rows[i]["to_do_msg"].ToString().Trim();
                string to_do_date = table.Rows[i]["to_do_date"].ToString().Trim();
                string to_min = table.Rows[i]["to_min"].ToString().Trim();
                string to_hr = table.Rows[i]["to_hr"].ToString().Trim();
                string added_by = table.Rows[i]["added_by"].ToString().Trim();
                string cus_deal_status = table.Rows[i]["cus_deal_status"].ToString().Trim();
                string cust_stat = table.Rows[i]["cust_stat"].ToString().Trim();
                string cust_reminder = table.Rows[i]["cust_reminder"].ToString().Trim();






                SqlCommand cmd1 = new SqlCommand("insert into task (p_id,t_id,deal_status,created,update_,min_,hrs,fast_reminder,day_,hr,min1,agent,sec_agent,rank,cust_rank,commission,sig,refer,cust_refer,comment,terms,to_do,cus_to_do,status_,full_day,to_do_msg,to_do_date,to_hr,to_min,added_by,cus_deal_status,cust_stat,cust_reminder) values  (@p_id ,@t_id ,@deal_status ,@created ,@update_ ,@min_ ,@hrs ,@fast_reminder ,@day_ ,@hr ,@min1 ,@agent ,@sec_agent ,@rank ,@cust_rank ,@commission ,@sig ,@refer ,@cust_refer ,@comment ,@terms ,@to_do ,@cus_to_do ,@status_ ,@full_day ,@to_do_msg ,@to_do_date ,@to_hr ,@to_min,@added_by,@cus_deal_status,@cust_stat,@cust_reminder)", conn);
                cmd1.Parameters.AddWithValue("@p_id ", pid);
                cmd1.Parameters.AddWithValue("@t_id ", t_id);
                cmd1.Parameters.AddWithValue("@deal_status ", deal_status);
                cmd1.Parameters.AddWithValue("@created ", created);
                cmd1.Parameters.AddWithValue("@update_ ", update_);
                cmd1.Parameters.AddWithValue("@min_", min_);
                cmd1.Parameters.AddWithValue("@hrs", hrs);
                cmd1.Parameters.AddWithValue("@fast_reminder", fast_reminder);
                cmd1.Parameters.AddWithValue("@day_ ", day_);
                cmd1.Parameters.AddWithValue("@hr", hr);
                cmd1.Parameters.AddWithValue("@min1", min1);
                cmd1.Parameters.AddWithValue("@agent", agent);
                cmd1.Parameters.AddWithValue("@sec_agent", sec_agent);
                cmd1.Parameters.AddWithValue("@rank", rank);
                cmd1.Parameters.AddWithValue("@cust_rank", cust_rank);
                cmd1.Parameters.AddWithValue("@commission", commission);
                cmd1.Parameters.AddWithValue("@sig", sig);
                cmd1.Parameters.AddWithValue("@refer", refer);
                cmd1.Parameters.AddWithValue("@cust_refer", cust_refer);
                cmd1.Parameters.AddWithValue("@comment", comment);
                cmd1.Parameters.AddWithValue("@terms", terms);
                cmd1.Parameters.AddWithValue("@to_do", to_do);
                cmd1.Parameters.AddWithValue("@cus_to_do", cus_to_do);
                cmd1.Parameters.AddWithValue("@status_ ", status_);
                cmd1.Parameters.AddWithValue("@full_day", full_day);
                cmd1.Parameters.AddWithValue("@to_do_msg", to_do_msg);
                cmd1.Parameters.AddWithValue("@to_do_date", to_do_date);
                cmd1.Parameters.AddWithValue("@to_hr", to_hr);
                cmd1.Parameters.AddWithValue("@to_min", to_min);

                cmd1.Parameters.AddWithValue("@added_by", Session["email"]);
                cmd1.Parameters.AddWithValue("@cus_deal_status", cus_deal_status);
                cmd1.Parameters.AddWithValue("@cust_stat", cust_stat);

                cmd1.ExecuteNonQuery();
            }
        }

        Session.Remove("p_id");
        Session["p_id"] = null;
        Session["t_id"] = null;

        table.Clear();
        Response.Redirect("property_add_confirmation.aspx");
    }
            
    

    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("property_add_confirmation.aspx");

    }


    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {

    }
}
//}


